//状态机模块
import {createStore} from 'vuex'
import { http } from '@/utils/http'
import user from './modules/user'

interface StoreType{
	num:number,
	userInfo:{
		"username":string
	},
	student:[
		{name:string,score:number}
	]
}

const store = createStore<StoreType>({
	modules:{
		"user":user//模块名 状态机模块
	},
	state:{
		num:111,
		userInfo:{
			"username":"问剑白玉京"
		},
		student:[
			{name:'杨敏',score:90}
		]
	},
	getters:{//负责对state中的数据进行加工处理 处理后返回新数据
		filterStu(state){
			return state.student.filter(item=>item.score>70)
		}
	},
	mutations:{
		//新增数据方法
		addStu(state,stu){
			state.student.push(stu)
		}
	},
	actions:{//异步操作
		async getStudent(context){
			let res = await http.get('/classes/Student')
			context.commit('addStu',res.data.results[0])
		}
	}
})

export default store

// export type StorType = ReturnType<typeof store>